'use strict';
const Service = require('egg').Service;

class NovelsList extends Service {
    /**
     * @params {name, author}
     * @bussiness {小说列表}
     * @author JC
     * @date 2022-08-15
     * **/
    async getAllNovels(params) {
        try {
            // 拿到书籍列表
            let novels = await this.app.mysql.select('novels', {
                where: {
                    lb: params.lb
                }
            })
            let signal = await this.app.mysql.select('novels', {
                where: {
                    id: params.id
                }
            })
            let state = await this.app.mysql.select('novels', {
                where: {
                    state: params.state,
                },
            })
            let lm = await this.app.mysql.select("novels", {
                limit: params.limit,
                offset: params.offset
            })
            let all = await this.app.mysql.select("novels")
            let result = [...novels, ...signal]
            if (params.lb || params.id) {
                return result
            } else if (params.state) {
                return state
            } else {
                return {
                    all,
                    lm,
                }
            }

        } catch (e) {
            return new Error('Error: ' + e.message)
        }
    }
}
module.exports = NovelsList;